/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VerSociosV2.java
 *
 * Created on Apr 20, 2011, 12:39:16 PM
 */

package forms;

import beans.Socio;
import dao.PersonaDao;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import util.SocioListModel;

/**
 *
 * @author nMoncho
 */
public class VerSociosV2 extends javax.swing.JFrame {

    private PantallaPrincipal pantalla;
    /** Creates new form VerSociosV2 */
    public VerSociosV2(PantallaPrincipal pantalla) {
        initComponents();
        this.pantalla = pantalla;
        
        listaSocios.updateUI();
        this.setLocation(100, 100);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        listaSocios = new javax.swing.JList();
        botonCerrar = new javax.swing.JButton();
        botonAgregar = new javax.swing.JButton();
        botonEditar = new javax.swing.JButton();
        botonBorrar = new javax.swing.JButton();
        labelBusqueda = new javax.swing.JLabel();
        textBusqueda = new javax.swing.JTextField();
        botonBuscar = new javax.swing.JButton();
        botonFiltrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Visualizar Socios");
        setIconImage(new ImageIcon(getClass().getResource("/resources/arrow-branch-bgr-16-ns.png")).getImage());

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        listaSocios.setModel(new SocioListModel(PersonaDao.getSocios()));
        listaSocios.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaSocios.setCellRenderer(new PanelVerSocio());
        jScrollPane1.setViewportView(listaSocios);

        botonCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/badge-square-cross-16-ns.png"))); // NOI18N
        botonCerrar.setText("Cerrar");
        botonCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCerrarActionPerformed(evt);
            }
        });

        botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/plus-16-ns.png"))); // NOI18N
        botonAgregar.setToolTipText("Crear Nuevo Socio");
        botonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarActionPerformed(evt);
            }
        });

        botonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/pencil-16.png"))); // NOI18N
        botonEditar.setToolTipText("Editar Socio seleccionado");
        botonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEditarActionPerformed(evt);
            }
        });

        botonBorrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/minus-16-ns.png"))); // NOI18N
        botonBorrar.setToolTipText("Borrar Socio seleccionado");

        labelBusqueda.setText("Legajo o Nombre:");

        botonBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/search-16-ns.png"))); // NOI18N
        botonBuscar.setToolTipText("Buscar Socio en lista");

        botonFiltrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/note-todo-list-16.png"))); // NOI18N
        botonFiltrar.setToolTipText("Filtrar lista de socios");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(labelBusqueda)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textBusqueda, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(botonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(botonFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(botonEditar, 0, 0, Short.MAX_VALUE)
                                .addComponent(botonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(botonBorrar, 0, 0, Short.MAX_VALUE)))
                    .addComponent(botonCerrar))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botonAgregar, botonBorrar, botonBuscar, botonEditar, botonFiltrar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(labelBusqueda)
                        .addComponent(textBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(botonBuscar)
                    .addComponent(botonFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(botonAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botonEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botonBorrar))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(botonCerrar)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {botonAgregar, botonBorrar, botonBuscar, botonEditar, botonFiltrar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_botonCerrarActionPerformed

    private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarActionPerformed
        pantalla.abrirVentana(PantallaPrincipal.AGREGAR_SOCIO);
    }//GEN-LAST:event_botonAgregarActionPerformed

    private void botonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEditarActionPerformed
        if(listaSocios.getSelectedValue() != null)
            pantalla.abrirVentanaEdicio((Socio)listaSocios.getSelectedValue());
        else
            JOptionPane.showMessageDialog(this, "Para editar un socio, antes seleccionalo de la lista", "Seleccion necesaria", JOptionPane.INFORMATION_MESSAGE+JOptionPane.OK_OPTION);
    }//GEN-LAST:event_botonEditarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VerSociosV2(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAgregar;
    private javax.swing.JButton botonBorrar;
    private javax.swing.JButton botonBuscar;
    private javax.swing.JButton botonCerrar;
    private javax.swing.JButton botonEditar;
    private javax.swing.JButton botonFiltrar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelBusqueda;
    private javax.swing.JList listaSocios;
    private javax.swing.JTextField textBusqueda;
    // End of variables declaration//GEN-END:variables

}
